<template>
  <div class="app-container">
    商城设置列表

    <el-table
      :data="this.list" stripe style="width: 100%">
      <el-table-column type="index" width="50" label="序号"/>
      <el-table-column prop="medcode" label="药品编号"/>
      <el-table-column prop="medname" label="药品名称"/>
      <el-table-column prop="medprice" label="药品价格"/>
      <el-table-column prop="availableNumber" label="库存"/>
      <el-table-column prop="param" label="备注"/>
      <el-table-column label="操作" width="280" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="mini"
                     icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除
          </el-button>
          <router-link :to="'/shop/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"></el-button>
          </router-link>

        </template>
      </el-table-column>

    </el-table>
    <router-link :to="'/shop/add/'">
      <el-button type="primary" icon="el-icon-circle-plus">新增</el-button>
    </router-link>
    <!-- 分页 -->
    <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>
</template>
<script>
import shop from '@/api/shop'

export default {
  data() {
    return {
      current: 1, //当前页
      limit: 3, //每页显示记录数
      searchObj: {}, //条件封装对象
      list: [], //每页数据集合
      total: 0,//总记录数
    }
  },
  created() {
    this.getList(this.current)
  },
  methods: {
    getList(page = 1) {//添加当前页参数
      this.current = page
      shop.getList(this.current)
        .then(response => {//接口返回数据
//返回集合list
          this.list = response.data.records
          console.log(this.list)
//总记录数
          this.total = response.data.total
        })//请求成功
        .catch(error => {//请求失败
          console.log(error)
        })
    },
    removeDataById(id) {
      this.$confirm('此操作将永久删除设置信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        shop.remove(id).then(response => {
//提示信息
          this.$message({

            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
      })
    }
  }
}
</script>
